class DanmakuSystem {
    constructor(player) {
        this.dp = player.dp;
        this.initEnhancedDanmaku();
    }

    /* 增强弹幕动画 */
    initEnhancedDanmaku() {
        // 覆盖DPlayer默认弹幕样式
        this.dp.danmaku.opacity = 0.92;
        this.dp.danmaku.speed = 8;
        
        // 添加3D透视效果
        this.dp.danmaku.container.style.perspective = '1000px';
        this.dp.danmaku.container.style.transformStyle = 'preserve-3d';
    }

    addDanmaku(text, options) {
        // 添加自定义动画类
        const danmaku = this.dp.danmaku.send({
            text,
            color: options.color || '#fff',
            type: options.type === 'scroll' ? 'right' : options.type
        });
        
        // 添加粒子效果
        if (options.effect === 'spark') {
            danmaku.element.classList.add('danmaku-spark');
            this.addSparkEffect(danmaku.element);
        }
    }

    /* 粒子效果实现 */
    addSparkEffect(element) {
        const sparks = document.createElement('div');
        sparks.className = 'spark-container';
        
        for (let i = 0; i < 8; i++) {
            const spark = document.createElement('div');
            spark.className = 'spark';
            sparks.appendChild(spark);
        }
        
        element.appendChild(sparks);
        setTimeout(() => sparks.remove(), 1000);
    }
}

export default DanmakuSystem;